/**
 * 
 */
package dms.service.imp;

import dms.model.role.Account;
import dms.repository.AccountRepository;
import dms.service.AccountService;

/**
 * @author 李健
 *
 */
public class AccountServiceImpl implements AccountService {

	private AccountRepository accountRepository = null;
	
	public AccountServiceImpl() {}
	@Override
	public void changePassword(String name, String newPassword) {
		this.accountRepository.changePassword(name, newPassword);
	}
	

	@Override
	/**
	 * if exist return true
	 * do not exist return false
	 */
	public boolean checkAccountExist(String name) {
		Account account = this.accountRepository.findAccountByName(name);
		if (account == null) {
			return false;
		}
		return true;
	}

	@Override
	public Account getAccount(long id) {
		return this.accountRepository.findAccountById(id);
	}
	
	public Account getAccount(String name) {
		return this.accountRepository.findAccountByName(name);
	}

	/**
	 * @param accountRepository
	 */
	public AccountServiceImpl(AccountRepository accountRepository) {
		super();
		this.accountRepository = accountRepository;
	}

	/**
	 * @return the accountRepository
	 */
	public AccountRepository getAccountRepository() {
		return accountRepository;
	}

	/**
	 * @param accountRepository the accountRepository to set
	 */
	public void setAccountRepository(AccountRepository accountRepository) {
		this.accountRepository = accountRepository;
	}

}
